package com.zmn.oms.zmn.business.interfaces.work.customwork;

import com.zmn.biz.engineer.common.query.distribute.DistributeOrderSkillQuery;
import com.zmn.oms.common.dio.redistribute.EngineerRedistributeQuery;
import com.zmn.oms.common.dro.conf.distribute.DistributeArgsDRO;
import com.zmn.oms.common.dro.conf.distribute.DistributeConfigDRO;
import com.zmn.oms.common.exception.OmsBaseException;
import com.zmn.oms.model.dto.work.distribute.MqWaitDistributeDTO;
import com.zmn.oms.model.entity.detail.OrderDetail;
import com.zmn.oms.model.entity.work.DistributeMasterQuery;
import com.zmn.oms.model.entity.work.OrderWork;
import com.zmn.oms.model.mongo.distribute.PlaceAnOrderPreDistribute;
import com.zmn.oms.model.mongo.distributesnapshot.DistributeSnapshot;
import com.zmn.oms.model.vo.work.DistributeReasonVO;
import com.zmn.oms.model.vo.work.DistributeSnapshotVO;
import com.zmn.oms.model.vo.work.DistributeVO;
import com.zmn.oms.model.vo.work.ZsOrderDistributeVO;
import java.util.Date;
import java.util.List;

/**
 * 类描述: 派单
 *
 * @author liuying
 * @date 2018/12/26 9:28 PM
 */
public interface ZsDistributeWorkBService {

    /**
     * 获取派单缘由
     *
     * @param orderId
     * @param workId
     * @param masterId
     * @return
     */
    DistributeReasonVO checkDistributeReason(Long orderId, Long workId, Integer masterId, boolean isGridDistribute);

    /**
     * 校验工程师不可派单原因
     *
     * @param distributeMasterQuery
     * @param distributeConfigDRO
     * @param isGridDistribute
     * @return
     */
    DistributeReasonVO checkDistributeReason(DistributeMasterQuery distributeMasterQuery, DistributeConfigDRO distributeConfigDRO, boolean isGridDistribute);

    /**
     * 存在服务中（已派单/已领单/已上门-进行中）相同位置、相同品类（前台二级产品分类）的其他工单 预约时间更相近工单的主工程师
     * @param orderWork
     * @param orderDetail
     * @return
     */
    ZsOrderDistributeVO findDutyRecentMaster(OrderWork orderWork, OrderDetail orderDetail, boolean isGridDistribute);



    /**
     * 查询派单工程师
     */
    void getOrderDistributeMasterList(OrderWork orderWork, OrderDetail orderDetail, DistributeVO distributeVO, DistributeArgsDRO distributeArgsDRO);

    /**
     * 查询基础工程师列表(师傅状态(包含停单中和请假中),不判断在线状态，服务范围)
     */
    List<ZsOrderDistributeVO> listBaseDistributeMaster(OrderWork orderWork, OrderDetail orderDetail);

    /**
     * 自动派单
     * @param orderWork
     * @param masterId：指定工程师
     */
    boolean autoDistribute(OrderWork orderWork, Integer masterId) throws OmsBaseException;

    /**
     * 队列定时派单消费
     * @param parseObject
     */
    void distributeConsume(MqWaitDistributeDTO parseObject);

    /**
     * 是否等待自动派单
     * @param orderWork
     */
    boolean isWaitAutoDistribute(OrderWork orderWork);

    /**
     * 是否天猫差异化派单
     * @param orderWork
     */
    boolean isTmallDistribute(OrderWork orderWork);

    /**
     * 是否天猫渠道
     * @param orderWork
     */
    boolean isTmallChannel(OrderWork orderWork);

    /**
     * 是否特殊服务商
     * @param orderWork
     */
    boolean isSpecialSp(OrderWork orderWork);

    /**
     * 获取派单参数
     * @param orderWork
     */
    DistributeArgsDRO getDistributeParam(OrderWork orderWork);

    /**
     * 根据工单信息生成派单视图对象
     * @param orderWork
     */
    DistributeVO buildDistributeVO(OrderWork orderWork, OrderDetail orderDetail, DistributeArgsDRO distributeArgsDRO);
    DistributeVO buildDistributeVO(OrderWork orderWork, OrderDetail orderDetail, DistributeArgsDRO distributeArgsDRO, boolean isGridDistribute);

    /**
     * 根据工单id和时间戳获取抢单快照
     * @param workId
     * @param snapshotId
     * @return
     */
    DistributeSnapshotVO buildDistributeSnapshotVO(Long workId, Long snapshotId);

    /**
     * 创建工程师接口技能列表
     * @param productId
     * @param showProductId
     * @param servCategId
     * @param categId
     */
    List<List<DistributeOrderSkillQuery>> buildSkillQueryLists(Integer productId, Integer showProductId, Integer servCategId, Integer categId);

    /**
     * 获取派单配置
     */
    DistributeConfigDRO getDistributeConfig(OrderWork orderWork);

    /**
     * 是否网格化派单
     */
    boolean isGridDistribute(OrderWork orderWork);

    /**
     * 通过派单参数判断是否网格化派单
     */
    boolean isGridDistributeByConfig(OrderWork orderWork);

    /**
     * 通过派单参数判断是否网格化派单
     */
    boolean isGridDistributeByConfig(DistributeConfigDRO distributeConfigDRO);


    /**
     * 网格化查询派单工程师
     */
    void gridGetOrderDistributeMasterList(OrderWork orderWork, OrderDetail orderDetail, DistributeVO distributeVO, DistributeConfigDRO distributeConfigDRO);

    /**
     * 查强制派单工程师列表
     */
    List<ZsOrderDistributeVO> listMandatoryDistributeMaster(OrderWork orderWork, OrderDetail orderDetail);

    /**
     * 保存派单快照
     * @param distributeSnapshot
     */
    void addDistributeSnapshot(DistributeSnapshot distributeSnapshot);

    /**
     * 保存不能自动派单原因
     * @param distributeVO
     * @param orderWork
     * @param date
     * @param message
     */
    void saveNonDistributeOrderLog(DistributeVO distributeVO, OrderWork orderWork, Date date, String message);

    /**
     * 获取预派工程师
     * @param distributeMasterQuery
     */
    DistributeVO getPreDistributeMaster(DistributeMasterQuery distributeMasterQuery);

    /**
     * 获取预约推荐工程师列表
     * @param distributeMasterQuery
     */
    DistributeVO listDutyRecommendMaster(DistributeMasterQuery distributeMasterQuery);

    /**
     * 获取下单预派单
     */
    PlaceAnOrderPreDistribute getPlaceAnOrderDistribute(Long workId);

    /**
     * 保存下单预派单
     * @param placeAnOrderPreDistribute
     */
    void addPlaceAnOrderDistribute(PlaceAnOrderPreDistribute placeAnOrderPreDistribute);

    /**
     * 构建查询派单工程师参数
     */
    DistributeMasterQuery buildDistributeMasterQuery(OrderWork orderWork, OrderDetail orderDetail, boolean isGridDistribute);

    /**
     * 查询服务商可派单工程师
     * @param distributeMasterQuery
     */
    List<ZsOrderDistributeVO> listSpDistributeMasterByQuery(DistributeMasterQuery distributeMasterQuery);

    /**
     * 获取重新分配工程师-平台直派-最优
     *   参考自动派单
     * @param orderWork
     * @param masterId 原工程师id
     * @return
     */
    ZsOrderDistributeVO getRedistributeMaster(OrderWork orderWork ,Integer masterId) throws OmsBaseException;

    /**
     * 获取重新分配工程师列表-平台直派-未排序
     *   参考自动派单
     * @param orderWork
     * @param orderDetail
     * @return
     */
    List<ZsOrderDistributeVO> getRedistributeMasterList(OrderWork orderWork, OrderDetail orderDetail);

    List<ZsOrderDistributeVO> getRedistributeMasterList(DistributeMasterQuery distributeMasterQuery, OrderWork orderWork, OrderDetail orderDetail);

    /**
     * 获取家修匠可服务工程师数量
     * @param orderWork
     * @param orderDetail
     * @return
     */
    Integer countJXJAvailableMaster(OrderWork orderWork, OrderDetail orderDetail);

    /**
     * 获取平台直派派单工程师-可根据distributeGrid切换查询
     * @param orderWork
     * @param orderDetail
     * @param engineerRedistributeQuery
     * @return
     */
    List<ZsOrderDistributeVO> getGridDistributeMasterList(OrderWork orderWork, OrderDetail orderDetail, EngineerRedistributeQuery engineerRedistributeQuery);

    /**
     * 获取订单改派视图
     *
     * @param orderWork
     * @param orderDetail
     * @param distributeVO
     * @param distributeConfigDRO
     */
    void gridGetOrderRedistributeVO(OrderWork orderWork, OrderDetail orderDetail, DistributeVO distributeVO, DistributeConfigDRO distributeConfigDRO);

    void gridGetOrderRedistributeVO(DistributeMasterQuery distributeMasterQuery, DistributeVO distributeVO, DistributeConfigDRO distributeConfigDRO);

}
